const fs = require('fs')

const express = require('express')
const router = express.Router()

const mongoose = require('mongoose')
const mongooseSchema = require('../model/mongooseSchemaToModel')
const ChoicesModel = mongooseSchema.ChoicesModel(mongoose)
//const blanModel = mongooseSchema.blankModel(mongoose)
//const drawModel = mongooseSchema.drawModel(mongoose)

const formidable = require('formidable');

/*********************************************  mulchoice  ***************************************************************/
router.post('/mulChoice', (req, res, next) => {

  const form = formidable({ multiples: true })
  //使用formidbale解析
  form.parse(req, (err, fields, files) => {
    if (err) {
      next(err)
      return
    }

    //解析没有问题的情况下保存到数据库
    ChoicesModel
      .create({
        //  title:{
        //    text:fields.title_text,  //题目
        //   pic:files.title_pic.path
        // },
        //  choices: {  //选项
        //      cho1: req.mulChoices.choices.cho1,
        //      cho2: req.mulChoices.choices.cho2,
        //      cho3: req.mulChoices.choices.cho3,
        //      cho4: req.mulChoices.choices.cho4,
        //  },
        // answer: req.mulChoices.answer,   //答案
        // analysis: req.mulChoices.analysis,  //解析
        // propety: req.mulChoices.propety, //所属章节知识点
      },
        function (err, data) {
          if (err) console.log(err)

          //console.log(data) // data 为成功保存到数据库中的数据
        })
    res.json({
      "errno": 0,
      "data": [
        "../tmp/upload_538d144fcfb1706d26eacc924ddcdbf0",
        "../tmp/upload_538d144fcfb1706d26eacc924ddcdbf0"
      ]
    })
    //res.send({ fields, files })  // 后期还需要改
  })
})


/*********************************************  mulchoice  ***************************************************************/




module.exports = router;





